using System;
using System.Collections;
using System.Web.UI;

using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;

namespace Jfc.DnnMarketingTools.MemberInvite
{
    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The Settings class manages Module Settings
    /// </summary>
    /// <remarks>
    /// </remarks>
    /// <history>
    /// </history>
    /// -----------------------------------------------------------------------------
    partial class Settings : ModuleSettingsBase
    {

        #region Base Method Implementations

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// LoadSettings loads the settings from the Database and displays them
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public override void LoadSettings()
        {
            try
            {
                if (Page.IsPostBack == false)
                {
                    ModuleController objModules = new ModuleController();
                    Hashtable settings = objModules.GetTabModuleSettings(TabModuleId);

                    int senderAddress = (int)SenderAddressType.User;
                    senderAddress = Convert.ToInt32(Null.GetNull(settings["SenderAddress"], senderAddress));

                    optSenderAddress.SelectedIndex = senderAddress;
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// UpdateSettings saves the modified settings to the Database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public override void UpdateSettings()
        {
            try
            {
                ModuleController objModules = new ModuleController();

                // Update Tab Module Settings
                string senderAddressString = Convert.ToString(optSenderAddress.SelectedIndex);

                if (!String.IsNullOrEmpty(senderAddressString))
                    objModules.UpdateTabModuleSetting(TabModuleId, "SenderAddress", senderAddressString);

                //refresh cache
#pragma warning disable 0618
                SynchronizeModule();
                //ModuleController.SynchronizeModule(ModuleId);
#pragma warning restore
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        #endregion

    }
}


